package datamanager

import (
	"cloudstaion/aliyun"
	"flag"
	"fmt"
	"github.com/go-playground/validator/v10"
	"log"
)

//ali对象参数
var (
	MendInt        string
	Ak             string
	Sk             string
	BucketName     string
	UploadFilePath string
	LocalFilePath  string
)

var (
	validate = validator.New()
)

type AliYun struct {

}

func NewAli() *AliYun{
	return &AliYun{}
}

func (a *AliYun)AliOssUploadFile() error{
	flag.StringVar(&MendInt,"m","","帮助")
	flag.StringVar(&Ak,"a","","帮助")
	flag.StringVar(&Sk,"s","","帮助")
	flag.StringVar(&BucketName,"b","","帮助")
	flag.StringVar(&UploadFilePath,"u","","帮助")
	flag.StringVar(&LocalFilePath,"l",UploadFilePath,"帮助")
	flag.Parse()

	fmt.Println(UploadFilePath)

	Obj := aliyun.NewAliYun(MendInt,
		Ak,
		Sk,
		BucketName,
		UploadFilePath,
		LocalFilePath)
	err := validate.Struct(Obj)
	if err != nil{
		validationErrors := err.(validator.ValidationErrors)
		// output: Key: 'User.Age' Error:Field validation for 'Age' failed on the 'lte' tag
		// fmt.Println(validationErrors)
		return fmt.Errorf("error: %v，Parse is valid",validationErrors)
	}
	log.Printf("创建实例成功-----")
	err = Obj.UploadFile()
	if err != nil {
		return err
	}
	return nil
}